home *** CD-ROM | disk | FTP | other *** search
- VB 3.0 Tips:
- Detecting End of Drag & Drops Sequences
- Michael D. Strathman
- MeV Technology, Inc.
-
- "Drag_and_drop would be considerably easier if the Visual Basic
- designers had provided a simple means to determine that a drop
- had been unsuccessful." Gary Wisniewski, "Drag 'til you Drop",
- April/May 1993 BASICPro Magazine, Fawcette Technical Publications.
-
- Microsoft in their invariable wisdom somehow chose to make the
- manual DRAG function operate rather counter-intuitively.
- That is, when an item is droped, the Mouse_Up function for the
- initiating subroutine is NOT called! This makes it very difficult
- to detect unsuccessful drops. Detecting an unsuccessful drop can
- be of importance when you need to update animation that may be in
- progress to support the Drag-Drop Sequence. To this end, this
- application note will suggest a very simple method for detecting
- the End_Of_Drag sequence. This technique work whether the
- operation was successful or not. One of its major benefits of
- this technique is that it does not require any custom control
- programming!
-
- The method involves generating the proper Mouse_Up event at the
- end of the drag operation. This can be accomplished using a
- single Windows API call and a normal Visual Basic Timer.
-
- The sequence is:
-
- 1) Enable a form timer in the Mouse_Down sequence after
- any animation steps but just before starting the
- manual Drag sequence,
- (remember to set the timer interval=5 or some value)
- (You can rename the timer ControlMouseUp if you like)
-
- 2) On each timer tick look to determine if the operator
- has released the mouse button.
-
- The steps are pretty simple: _________________________________
- '*** Put a timer named ControlMouseUp on your form
-
- '**** In a .BAS form (as you will probably use this elsewhere) Declare the API Function
- Declare Function GetKeyState Lib "User" (ByVal nKey As Integer) As Integer
-
- '**** In the code sequence for the control of Interest
- Sub Control_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
-
- FileCabinet = FileOpenIcon '*** Animation, transfer image from one Box to another
- Control.DragIcon = AnyIcon '*** Set up the Drag Icon
- ControlMouseUp.Enabled = True '*** Enable the Timer (Put on the form at Design Time)
- Control.Drag 1 '*** Start the manual Drag Operation
-
- End Sub
-
- '***** In the form Timer Event Code Section
- ' This is the NEW Mouse_Up Routine!
- Sub ControlMouseUp_Timer ()
-
- K% = 1 '*** Set the Virtual Scan code for the Mouse Left Button
- I% = GetKeyState(K%) '*** Get the Key state
- I% = I% And (Not 1) '*** Mask off the unimportant Bits
- If I% = 0 Then '*** Test to see if the operator has released the mouse button
- '*** Mouse_Up Detected!
- FileCabinet = FileClosed '*** Finish animation, by transferring images
- ControlMouseUp.Enabled = 0 '*** Turn off the timer so this event will not be triggered
- End If
-
- End Sub
- ______________________________________________________________
-
- Author:
- Michael D. Strathman
- MeV Technolgy, Inc.
- 5150 Shadow Estates
- San Jose, CA 95135
- Ph. (408) 238-6351
- Fax: (408) 238-3466
- Compuserve: 75663,520
-